<?php

/*
 *51M网 邮件发送类
 * */
class AoMai_email
{


    function weimek_emailfun($to, $subject = "", $body = "")
    {
        //$to 表示收件人地址 $subject 表示邮件标题 $body表示邮件正文
        //error_reporting(E_ALL);
        error_reporting(E_STRICT);
        date_default_timezone_set("Asia/Shanghai");//设定时区东八区
        require_once(ROOT_PATH . 'includes/email/class.phpmailer.php');
        include(ROOT_PATH . 'includes/email/class.smtp.php');
        $mail = new PHPMailer(); //new一个PHPMailer对象出来
        $body = $body; //对邮件内容进行必要的过滤
        $mail->CharSet = "UTF-8";//设定邮件编码，默认ISO-8859-1，如果发中文此项必须设置，否则乱码
        $mail->IsSMTP(); // 设定使用SMTP服务
        $mail->SMTPDebug = 0;                     // 启用SMTP调试功能
        // 1 = errors and messages
        // 2 = messages only

        $smtpserver = C('email_server');
        $port = C('email_port');
        $smtpuser = C('email_user');
        $smtppwd = C('email_pwd');

        $mail->SMTPAuth = true;                  // 启用 SMTP 验证功能

        //是否为安全链接
        $email_is_ssl = C('email_is_ssl')=="true"?1:0;
        if($email_is_ssl){
            $mail->SMTPSecure = "ssl";                 // 安全协议
        }else{

        }

        $mail->Host =$smtpserver;      // SMTP 服务器
        $mail->Port = $port;                   // SMTP服务器的端口号
        $mail->Username = $smtpuser;  // SMTP服务器用户名
        $mail->Password = $smtppwd;            // SMTP服务器密码
        $mail->SetFrom($smtpuser, "51M网");
        // $mail->AddReplyTo("281@qq.com", "邮件回复人的名称");
        $mail->Subject = $subject;
        $mail->AltBody = "www.51m.com.au"; // optional, comment out and test
        $mail->MsgHTML($body);
        $address = $to;
        $mail->AddAddress($address,$to);
        //添加附件
        //$mail->AddAttachment(THINK_PATH . 'Common/email/class.smtp.php');      // attachment
        //$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment
        if (!$mail->Send()) {
            // echo "Mailer Error: " . $mail->ErrorInfo;
        } else {
            // echo "Message sent!恭喜，邮件发送成功！";
        }
    }

  function weimek_emailfun_atta($to, $subject = "", $body = "",$attachmentpath="")
    {


        //$to 表示收件人地址 $subject 表示邮件标题 $body表示邮件正文
        //error_reporting(E_ALL);
        error_reporting(E_STRICT);
        date_default_timezone_set("Asia/Shanghai");//设定时区东八区
        require_once($_SERVER['DOCUMENT_ROOT'] . '/includes/email/class.phpmailer.php');
        include($_SERVER['DOCUMENT_ROOT'] . '/includes/email/class.smtp.php');

        $mail = new PHPMailer(); //new一个PHPMailer对象出来
        $body = $body; //对邮件内容进行必要的过滤
        $mail->CharSet = "UTF-8";//设定邮件编码，默认ISO-8859-1，如果发中文此项必须设置，否则乱码
        $mail->IsSMTP(); // 设定使用SMTP服务
        $mail->SMTPDebug = 0;                     // 启用SMTP调试功能
        // 1 = errors and messages
        // 2 = messages only




        $smtpserver = "smtp.exmail.qq.com";
        $port = "465";
        $smtpuser = "service@aomai.com.au";
        $smtppwd = "aozhoumama902";

        $mail->SMTPAuth = true;                  // 启用 SMTP 验证功能

        //是否为安全链接
     
        $mail->SMTPSecure = "ssl";                 // 安全协议
     

        $mail->Host =$smtpserver;      // SMTP 服务器
        $mail->Port = $port;                   // SMTP服务器的端口号
        $mail->Username = $smtpuser;  // SMTP服务器用户名
        $mail->Password = $smtppwd;            // SMTP服务器密码
        $mail->SetFrom($smtpuser, "51M网");
        // $mail->AddReplyTo("281@qq.com", "邮件回复人的名称");
        $mail->Subject = $subject;
        $mail->AltBody = "www.51m.com.au"; // optional, comment out and test
        $mail->MsgHTML($body);
        $address = $to;
        $mail->AddAddress($address,$to);
        //添加附件
     //  $mail->AddAttachment(THINK_PATH . 'Common/email/class.smtp.php');      // attachment
      //  $mail->AddAttachment($attachmentpath); // attachment

         $status_eamil  =  $mail->Send();

        if (!$status_eamil) {
//            echo "Mailer Error: " . $mail->ErrorInfo;
        } else {
//            echo "Message sent!恭喜，邮件发送成功！";
        }



    }
	
	//参数为数组 $to, $subject = "", $body = "",$attachmentpath=""
	
	function weimek_emailfun_atta_arr($ary=array())
    {
        //$to 表示收件人地址 $subject 表示邮件标题 $body表示邮件正文
        //error_reporting(E_ALL);
        error_reporting(E_STRICT);
        date_default_timezone_set("Asia/Shanghai");//设定时区东八区
        require_once($_SERVER['DOCUMENT_ROOT'] . '/includes/email/class.phpmailer.php');
        include($_SERVER['DOCUMENT_ROOT'] . '/includes/email/class.smtp.php');

        $mail = new PHPMailer(); //new一个PHPMailer对象出来
        $body = $ary['body']; //对邮件内容进行必要的过滤
        $mail->CharSet = "UTF-8";//设定邮件编码，默认ISO-8859-1，如果发中文此项必须设置，否则乱码
        $mail->IsSMTP(); // 设定使用SMTP服务
        $mail->SMTPDebug = 0;                     // 启用SMTP调试功能
        // 1 = errors and messages
        // 2 = messages only
        $mail->SMTPKeepAlive = true;
        $smtpserver = "smtp.exmail.qq.com";
        $port = "465";
        $smtpuser = "service@aomai.com.au";
        $smtppwd = "aozhoumama902";

        $mail->SMTPAuth = true;                  // 启用 SMTP 验证功能

        //是否为安全链接
     
        $mail->SMTPSecure = "ssl";                 // 安全协议
     
        $mail->Host =$smtpserver;      // SMTP 服务器
        $mail->Port = $port;                   // SMTP服务器的端口号
        $mail->Username = $smtpuser;  // SMTP服务器用户名
        $mail->Password = $smtppwd;            // SMTP服务器密码
        $mail->SetFrom($smtpuser, "51M网");
        // $mail->AddReplyTo("281@qq.com", "邮件回复人的名称");
        $mail->Subject = $ary['subject'];
        $mail->Body = $ary['body'];
        $mail->AltBody = "www.51m.com.au"; // optional, comment out and test
        $mail->MsgHTML($body);
        //$address = $ary['to'];
		foreach($ary['people'] as $key => $val)
		{
			
			$mail->AddAddress($val['to'],$val['subject']);
			
		}
        //添加附件
        //$mail->AddAttachment(str_replace("\\","/",THINK_PATH) . 'Common/email/class.smtp.php');      // attachment
       if(is_array($ary['attachmentpath']))
	   {
		   //多个附件
		   foreach($ary['attachmentpath'] as $key =>$val)
		   {
			   $mail->AddAttachment($val); // attachment,附件地址
		   //$mail->AddAttachment($ary['attachmentpath'][1]); // attachment,附件地址
		   }
	   }
	   
       else
	   {
		   $mail->AddAttachment($ary['attachmentpath']); // attachment,附件地址
	   }
		//$mail->IsHTML(true);
        $status_eamil  =  $mail->Send();

        if (!$status_eamil) {
            //echo "Mailer Error: " . $mail->ErrorInfo;
            return array("error"=>0,"message"=>"Mailer Error: " . $mail->ErrorInfo);
        } else {
           //echo "Message sent!恭喜，邮件发送成功！";
		   return array("error"=>1,"Message sent!恭喜，邮件发送成功！"); 
        }

    }


}